package com.dsh.admin.dao.impl;

import java.util.List;

import javax.annotation.Resource;

import org.mybatis.spring.SqlSessionTemplate;
import org.springframework.stereotype.Repository;

import com.dsh.admin.dao.ShopUserDao;
import com.dsh.admin.entity.ShopUser;

@Repository
public class ShopUserDaoImpl implements ShopUserDao {
	
	
	/**
	 * 检查用户名和密码
	 * @return
	 */
	@Override
	public ShopUser checkUsernameAndPwd(ShopUser bean) {
		List<ShopUser> list = sqlSession.selectList("shopUserMap.checkUsernameAndPwd",bean);
		if(list.size()>0){
			return list.get(0);
		}
		return null;
	}
	
	/**
	 * 通过id查询对应的管理员信息
	 * @param id
	 * @return
	 */
	public ShopUser findById(Integer id){
		ShopUser bean = sqlSession.selectOne("shopUserMap.findById",id);
		return bean;
	}
	
	/**
	 * 更新
	 * @param bean
	 * @return
	 */
	public ShopUser update(ShopUser bean){
		sqlSession.update("shopUserMap.updateByBean", bean);
		bean = findById(bean.getId());
		return bean;
	}
	
	@Resource(name="sqlSession")
	private SqlSessionTemplate sqlSession;
}
